import dayjs from 'dayjs'
import utc from 'dayjs/plugin/utc'
//dayjs不支持utc，需要扩展
dayjs.extend(utc)

const DATE_TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss'

export function formatUtcString(
  utcString: string,
  format: string = DATE_TIME_FORMAT
) {
  return dayjs.utc(utcString).utcOffset(8).format(format)
}

//时间戳的使用方式
export function formatTimeStamp(
  timeStamp: number,
  format: string = DATE_TIME_FORMAT
) {
  return dayjs(timeStamp).format(format)
}

// // 时间戳
// const timestamp = 234566788989
// // 创建Date对象
// const date = new Date(timestamp)
// // 获取年月日时分秒
// const year = date.getFullYear()
// const month = date.getMonth() + 1
// const day = date.getDate()
// const hour = date.getHours()
// const minute = date.getMinutes()
// const second = date.getSeconds()

// // 输出结果
// const newDate = `${year}-${month}-${day} ${hour}:${minute}:${second}`
